package com.web;


import com.MessageService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/messagelist")
public class MessageListController {
    @Resource
    private MessageService messageService;

    @RequestMapping("/messagelist")
    public String add(HttpServletRequest request, @RequestParam(value = "messagebox") String message) {
        HttpSession session = request.getSession(true);
        String name = (String) session.getAttribute("nickname");

        if (message != null && name != null) {
            messageService.addMessage(message, name);
            return "chat";
        } else {
            return "start";
        }
    }
}
